#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define LL long long
using namespace std;

const int kMaxN = 1e5 + 10;

struct SparseTable {
 private:
  int len;
  vector<vector<int>> st;
  vector<int> to_dep;

 public:
  void Construct(const vector<int>& num) {
    len = num.size();
    int d;

    to_dep.resize(len, 0);
    for (d = 0; (1 << d) <= len; d++) {
      to_dep[(1 << d) - 1] = d;
    }
    for (int i = 2; i < len; i++) {
      if (!to_dep[i]) {
        to_dep[i] = to_dep[i - 1];
      }
    }

    st.resize(d, num);
    for (int i = 1; i < d; i++) {
      for (int j = 0; j + (1 << i) <= len; j++) {
        st[i][j] = max(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
      }
    }
  }
  SparseTable(const vector<int>& num = {}) {
    Construct(num);
  }
  int GetMax(int l, int r) {
    int d = to_dep[r - l];

    return max(st[d][l], st[d][r - (1 << d) + 1]);
  }
};

struct Tree {
  int n;
  vector<int> e[kMaxN];
  vector<int> depth, diameter;
  vector<int> dist_end, dist_start;
  vector<int> dist, idx;
  SparseTable st1, st2;
  Tree(int _n) {
    n = _n;
    depth.resize(n + 1);
  }

  void Add(int u, int v) {
    e[u].push_back(v);
    e[v].push_back(u);
  }

  void DFS(int now, int dep) {
    depth[now] = dep;
    for (int next : e[now]) {
      if (depth[next] == 0) {
        DFS(next, dep + 1);
      }
    }
  }

  void GetDiameter() {
    int maxd = 0;

    for (int i = 1; i <= n; i++) {
      maxd = max(maxd, depth[i]);
    }
    for (int i = 1; i <= n; i++) {
      if (depth[i] == maxd) {
        int now = i;

        diameter.push_back(now);
        while (depth[now] > 1) {
          for (int next : e[now]) {
            if (depth[next] + 1 == depth[now]) {
              now = next;
              break;
            }
          }
          diameter.push_back(now);
        }
        break;
      }
    }
  }

  void CalcDiameter() {
    DFS(1, 1);

    int maxd = 0;

    for (int i = 1; i <= n; i++) {
      maxd = max(maxd, depth[i]);
    }
    for (int i = 1; i <= n; i++) {
      if (depth[i] == maxd) {
        fill(depth.begin(), depth.end(), 0);
        DFS(i, 1);
        dist_end = depth;
        GetDiameter();
        fill(depth.begin(), depth.end(), 0);
        DFS(diameter[0], 1);
        dist_start = depth;
        break;
      }
    }
    for (int i = 1; i <= n; i++) {
      dist_end[i]--;
      dist_start[i]--;
    }
  }

  void DFS2(int now, int id, int dis) {
    dist[now] = dis;
    idx[now] = id;
    for (int next : e[now]) {
      if (idx[next] == -1) {
        DFS2(next, id, dis + 1);
      }
    }
  }

  void CalcDist2Diameter() {
    idx.resize(n + 1, -1);
    dist.resize(n + 1);
    for (int i = 0; i < diameter.size(); i++) {
      int now = diameter[i];

      idx[now] = i;
    }
    for (int now : diameter) {
      DFS2(now, idx[now], 0);
    }
  }

  void CalcST() {
    vector<int> num(diameter.size(), 0);

    for (int i = 1; i <= n; i++) {
      num[idx[i]] = max(dist[i], num[idx[i]]);
    }
    for (int i = 0; i < num.size(); i++) {
      num[i] += i;
    }
    st1.Construct(num);
    for (int i = 0; i < num.size(); i++) {
      num[i] -= i * 2;
    }
    st2.Construct(num);
  }
  int GetAns(int u, int v) {
    int ans = max(min(dist_start[u], dist_start[v]), min(dist_end[u], dist_end[v]));

    if (idx[u] > idx[v]) {
      swap(u, v);
    }
    if (idx[u] != idx[v]) {
      ans = max(ans, (idx[v] - idx[u]) / 2);
      int disuv = dist[u] + dist[v] + (idx[v] - idx[u]);

      disuv /= 2;
      if (dist[u] < disuv) {
        ans = max(ans, st1.GetMax(idx[u], idx[u] + (disuv - dist[u])) - idx[u] + dist[u]);
      }
      if (dist[v] < disuv) {
        ans = max(ans, st2.GetMax(idx[v] - (disuv - dist[v]), idx[v]) + idx[v] + dist[v]);
      }
    }
    return ans;
  }
};

int main() {
  freopen("tree.in", "r", stdin);
  freopen("tree.out", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;

  cin >> n;
  Tree tree(n);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    tree.Add(u, v);
  }
  tree.CalcDiameter();
  tree.CalcDist2Diameter();
  tree.CalcST();

  for (cin >> m; m; m--) {
    int u, v;

    cin >> u >> v;
    cout << tree.GetAns(u, v) << "\n";
  }
  return 0;
}